package com.celesea.framework.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * ${DESCRIPTION}
 *
 * @author JackYuan
 * @create 2017-10-25 18:14
 */
@ApiModel(value = "排序条件")
public class Sort implements Serializable {
    /**
     * 升序
     */
    public static final String ASC = "ASC";
    /**
     * 降序
     */
    public static final String DESC = "DESC";

    @ApiModelProperty(value = "排序字段")
    public String sortField;
    @ApiModelProperty(value = "排序方式")
    public String sortType;

    public Sort() {

    }

    public Sort(String field, String type) {
        this.sortField = field;
        this.sortType = type;
    }

    public String getSortField() {
        return sortField;
    }

    public void setSortField(String sortField) {
        this.sortField = sortField;
    }

    public String getSortType() {
        return sortType;
    }

    public void setSortType(String sortType) {
        this.sortType = sortType;
    }

    public boolean isSort() {
        return StringKit.isNotEmpty(sortField);
    }

    public String toSort() {
        StringBuffer buffer = new StringBuffer();
        if (this.isSort()) {
//            buffer.append(" ORDER BY ").append(StringKit.ingoreKeyword(sortField));
            buffer.append(StringKit.ingoreKeyword(sortField));
            if (StringKit.isNotEmpty(sortType)) {
                buffer.append(sortType);
            }
        }
        return buffer.toString();
    }
}
